/**
 *
 * @author John Creecy
 */
package battlebarnchat;


import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class BattleBarnChat implements Runnable, ActionListener {

	public JTextField inputField;

	public BattleBarnChat() {
		inputField =  new JTextField(60);
		inputField.addActionListener(this);
	}

	public void addComponentsToPane(Container pane) {
		pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
		Main.statusMessage.setAlignmentX(Component.CENTER_ALIGNMENT);
		pane.add(Main.statusMessage);
		inputField.setAlignmentX(Component.CENTER_ALIGNMENT);
		pane.add(inputField);

	}

	private void createAndShowGUI() {
		JFrame frame = new JFrame("BattleBarn Chat");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		addComponentsToPane(frame.getContentPane());
		frame.pack();
		frame.setVisible(true);
	}

	public void run() {
		createAndShowGUI();
	}

	public void actionPerformed(ActionEvent e) {
		SendChatMessage sendChatMessage = new SendChatMessage(inputField.getText());
		sendChatMessage.run();
		inputField.setText(null);
	}
}
